import { defineStore } from 'pinia'
import api from '@/api/index.js'
export const useUserStore = defineStore({
  id: 'user', // id必填，且需要唯一
  state: () => {
    return {
      uid:0,
      cookie: '',
      userInfo: {},
      isShowUserInfo: false,
      playList: [],
      keywords: '',
      result: {},
      isDark:true
    }
  },
  actions: {
    saveUid(uid) {
      this.uid=uid
    },
    saveCookie(cookie) {
      this.cookie=cookie
    },
    saveUserInfo(key, value) {
      this.userInfo[key]=value
    },
    setShowUserInfo(is) {
      this.isShowUserInfo=is
    },
    saveplayList(playList) {
      this.playList=playList
    },
    saveKeywords(keywords) {
      this.keywords=keywords
    },
    async searchResult(keywords) {
      let {result} =await api.getSearchResult({ keywords })
      this.result=result
    },
    setDark(val) {
      this.isDark=val
    }
  },
  // 开启数据缓存
  persist: {
    enabled: true
  }
})
